package com.everyday.practice.algorithm;

/**
 * @description:
 * @author: leon
 * @time: 2021/4/7 17:01
 */
public class Title844 {
    public static void main(String[] args) {
        boolean b = backspaceCompare("ab##", "c#d#");
        System.out.println(b);
    }

    public static boolean backspaceCompare(String s, String t) {
        String s1 = backSpace(s);
        String s2 = backSpace(t);
        return s1.equals(s2);
    }

    public static String backSpace(String str) {
        String[] split = str.split("");
        StringBuilder sb = new StringBuilder("");
        for (String s : split) {
            if (s.equals("#")){
                if (sb.length()>0){
                    sb.deleteCharAt(sb.length()-1);
                }
            }else{
                sb.append(s);
            }
        }
        return sb.toString();
    }
}
